home *** CD-ROM | disk | FTP | other *** search
Text File | 1993-07-11 | 5.6 KB | 268 lines | [TEXT/KAHL] |
- ///--------------------------------------------------------------------------------------
- // Simple.c
- //
- // By: Tony Myles
- //
- // Copyright © 1993 Tony Myles, All rights reserved worldwide.
- ///--------------------------------------------------------------------------------------
-
-
- #ifndef __DESK__
- #include <Desk.h>
- #endif
-
- #ifndef __EVENTS__
- #include <Events.h>
- #endif
-
- #ifndef __OSEVENTS__
- #include <OSEvents.h>
- #endif
-
- #ifndef __TOOLUTILS__
- #include <ToolUtils.h>
- #endif
-
- #ifndef __SEGLOAD__
- #include <SegLoad.h>
- #endif
-
- #ifndef __WINDOWS__
- #include <Windows.h>
- #endif
-
- #ifndef __SPRITEWORLD__
- #include <SpriteWorld.h>
- #endif
-
- #ifndef __SPRITELAYER__
- #include <SpriteLayer.h>
- #endif
-
- #ifndef __SPRITE__
- #include <Sprite.h>
- #endif
-
- #ifndef __FRAME__
- #include <Frame.h>
- #endif
-
- #ifndef __SPRITEWORLDUTILS__
- #include <SpriteWorldUtils.h>
- #endif
-
- #ifndef __APPLICATION__
- #include "Application.h"
- #endif
-
- #ifndef __SIMPLE__
- #include "Simple.h"
- #endif
-
- #include "Globals.h"
-
- ///--------------------------------------------------------------------------------------
- // PrepareSimpleAnimation
- ///--------------------------------------------------------------------------------------
-
- void PrepareSimpleAnimation (void)
- {
- OSErr err;
- GrafPtr savePort;
-
- GetPort(&savePort);
- SetPort((GrafPtr)curWindow);
- SetCursor(*GetCursor(watchCursor));
-
-
- //
- // STEP #1: initialize the sprite world package
- //
-
- err = SWEnterSpriteWorld();
- FatalError(err);
-
-
- //
- // STEP #2: create the various pieces that we need
- //
-
- // create the sprite world
- err = SWCreateSpriteWorldFromWindow(&(cur->spriteWorldP), (CWindowPtr)curWindow, NULL);
- FatalError(err);
-
- // create the sprite layer
- err = SWCreateSpriteLayer(&(cur->spriteLayerP));
- FatalError(err);
-
- // create the first sprite
- err = SWCreateSpriteFromPictResource(&(cur->simpleSpriteP), NULL, 1000,1000,
- 6, kRegionMask);
- FatalError(err);
- cur->simpleSpriteArray[0] = cur->simpleSpriteP;
-
- // clone the rest of the sprites off the first one
- for (cur->spriteNum = 1; cur->spriteNum < kNumberOfSprites; cur->spriteNum++)
- {
- err = SWCloneSprite(cur->simpleSpriteP, cur->simpleSpriteArray + cur->spriteNum, NULL);
- FatalError(err);
- }
-
-
- //
- // STEP #3: put the pieces together (must be done BEFORE the sprite world is locked!)
- //
-
- for (cur->spriteNum = 0; cur->spriteNum < kNumberOfSprites; cur->spriteNum++)
- {
- // add the sprite to the layer
- SWAddSprite(cur->spriteLayerP, cur->simpleSpriteArray[cur->spriteNum]);
- }
-
- // add the layer to the world
- SWAddSpriteLayer(cur->spriteWorldP, cur->spriteLayerP);
-
-
- //
- // STEP #4: set things up for the animation
- //
-
- // calculate the movement boundary rectangle
- cur->moveBoundsRect = cur->spriteWorldP->windowFrameP->frameRect;
-
- for (cur->spriteNum = 0; cur->spriteNum < kNumberOfSprites; cur->spriteNum++)
- {
- cur->simpleSpriteP = cur->simpleSpriteArray[cur->spriteNum];
- cur->moveSpeed = cur->moveSpeedArray[cur->spriteNum];
-
- // set up the sprite
- SWSetSpriteMoveBounds(cur->simpleSpriteP, &(cur->moveBoundsRect));
- SWSetSpriteMoveTime(cur->simpleSpriteP, (long)cur->moveSpeed);
- SWSetSpriteMoveProc(cur->simpleSpriteP, SWBounceSpriteMoveProc);
- SWSetSpriteMoveDelta(cur->simpleSpriteP, kHorizMoveDelta, kVertMoveDelta);
-
- SWSetSpriteFrameAdvance(cur->simpleSpriteP, 1);
- SWSetSpriteFrameRange(cur->simpleSpriteP, 1,5);
- SWSetCurrentFrameIndex(cur->simpleSpriteP, 0);
- SWSetSpriteFrameTime(cur->simpleSpriteP, (long)cur->moveSpeed);
-
- // set the sprite’s initial location
- SWSetSpriteLocation(cur->simpleSpriteP, cur->spriteNum * 60, cur->spriteNum * 60);
- }
-
-
-
-
- //
- // STEP #5: lock the sprite world !!! VERY IMPORTANT !!!
- //
-
- SWLockSpriteWorld(cur->spriteWorldP);
-
-
-
- SetPort(savePort);
- ShowCursor();
- SetCursor(&qd.arrow);
-
- }
-
-
-
-
- ///--------------------------------------------------------------------------------------
- // PerformSimpleAnimation
- ///--------------------------------------------------------------------------------------
-
- void PerformSimpleAnimation (void)
- {
- GrafPtr savePort;
-
- GetPort(&savePort);
- SetPort((GrafPtr)curWindow);
-
- if (curWindow != 0){
-
- //
- // STEP #6: run the animation
- //
-
- // update the window
-
- SWUpdateSpriteWorld(cur->spriteWorldP);
- SWProcessSpriteWorld(cur->spriteWorldP);
- SWAnimateSpriteWorld(cur->spriteWorldP);
-
- }
-
- SetPort(savePort);
-
-
- }
-
-
-
-
-
-
- ///--------------------------------------------------------------------------------------
- // EndSimpleAnimation
- ///--------------------------------------------------------------------------------------
-
- void EndSimpleAnimation (void)
- {
-
-
- //
- // STEP #7: unlock the sprite world
- //
-
- SWUnlockSpriteWorld(cur->spriteWorldP);
-
- //
- // STEP #8: dispose of the pieces we created
- //
-
- for (cur->spriteNum = 0; cur->spriteNum < kNumberOfSprites; (cur->spriteNum)++)
- {
- SWDisposeSprite(cur->simpleSpriteArray[cur->spriteNum], cur->spriteNum == 0);
- }
-
- SWDisposeSpriteLayer(cur->spriteLayerP);
- SWDisposeSpriteWorld(cur->spriteWorldP);
-
-
- //
- // STEP #9: shut down the sprite world package
- //
-
- SWExitSpriteWorld();
-
-
- }
-
-
- ///--------------------------------------------------------------------------------------
- // ChangeMoveSpeed
- ///--------------------------------------------------------------------------------------
-
- void ChangeMoveSpeed (void)
- {
- SWUnlockSpriteWorld(cur->spriteWorldP);
- for (cur->spriteNum = 0; cur->spriteNum < kNumberOfSprites; cur->spriteNum++)
- {
- cur->simpleSpriteP = cur->simpleSpriteArray[cur->spriteNum];
- cur->moveSpeed = cur->moveSpeedArray[cur->spriteNum];
-
- SWSetSpriteMoveTime(cur->simpleSpriteP, (long)cur->moveSpeed);
- SWSetSpriteFrameTime(cur->simpleSpriteP, (long)cur->moveSpeed);
- }
-
- SWLockSpriteWorld(cur->spriteWorldP);
- }
-
-
-
-
-
-